var right_id = false;
var right_passwords = false;
var right_email = false;
var right_phone = false;
var right_name = false;
var right_addr = false;
window.onload = init;
function init()
{
document.getElementById("memberId").onblur = chkId;
document.getElementById("memberPasswd").onblur = chkPasswords;
document.getElementById("memberconfirPasswd").onblur = chkConfpasswords;
document.getElementById("memberEmail").onblur = chkEmail;
document.getElementById("memberPhone").onblur = chkPhone;
document.getElementById("memberName").onblur = chkName;
document.getElementById("register").onsubmit = check;
}
///////////////////帐号///////////////////////
function chkId()
{
   var id = document.getElementById("memberId").value;
   if(id.length >3 &&id.length<9)
   {
    right_id = true;
    document.getElementById("idcheck").src="images/right.jpg";
    document.getElementById("idcheck").style.display="";
    document.getElementById("id_check_label").innerHTML = "";
   }
    else 
   {
    right_id = false;
    document.getElementById("idcheck").src="images/error.jpg";
    document.getElementById("idcheck").style.display="";
    document.getElementById("id_check_label").innerHTML = "请输入账号(4~8位)";
   }
}
/////////////////////密码///////////////////////
function chkPasswords()
{
  var init = document.getElementById("memberPasswd");
  var sec = document.getElementById("memberconfirPasswd");
  if(""==init.value)
  {
	   //alert("You did not enter a password \n"+"Please enter one now");
         document.getElementById("passwordcheck").src="images/error.jpg";
         document.getElementById("passwordcheck").style.display="";
         document.getElementById("password_check_label").innerHTML = "请输入密码！";
	   //init.focus();
	   //return false;
	     right_passwords = false;
	   return;
	   
  }
else if(sec.value == "")
{ 
         document.getElementById("passwordcheck").src="images/right.jpg";
         document.getElementById("passwordcheck").style.display="";
         document.getElementById("password_check_label").innerHTML = "";
         right_passwords  = true;
}
else if(init.value == sec .value)
  {
       right_passwords = true;
	   document.getElementById("passwordcheck").src="images/right.jpg";
       document.getElementById("passwordcheck").style.display="";
       document.getElementById("password_check_label").innerHTML = "";
       document.getElementById("passwordconfircheck").src="images/right.jpg";
       document.getElementById("passwordconfircheck").style.display="";
       document.getElementById("passwordconfir_check_label").innerHTML = "";
  
         
  }
  else
  {
         document.getElementById("passwordcheck").src="images/right.jpg";
         document.getElementById("passwordcheck").style.display="";
         document.getElementById("password_check_label").innerHTML = "";
	   //alert("The two passwords you entered are not the same \n" + "Please re_enter both now");
          document.getElementById("passwordconfircheck").src="images/error.jpg";
          document.getElementById("passwordconfircheck").style.display="";
          document.getElementById("passwordconfir_check_label").innerHTML = "两次密码不一致！";
	   //init.focus();
	  // init.select();
	   //return false;
	    right_passwords = false;
  }
		  //return true;
	   
}
///////////////////////////////////////////////

function chkConfpasswords()
{
  var init = document.getElementById("memberPasswd");
  var sec = document.getElementById("memberconfirPasswd");
  if(sec.value == "")
  {
          document.getElementById("passwordconfircheck").src="images/error.jpg";
          document.getElementById("passwordconfircheck").style.display="";
          document.getElementById("passwordconfir_check_label").innerHTML = " 输入确认密码！";
          right_passwords = false;
           return ;
  }
  else if(init.value == sec .value)
  {
       right_passwords = true;
       document.getElementById("passwordconfircheck").src="images/right.jpg";
       document.getElementById("passwordconfircheck").style.display="";
       document.getElementById("passwordconfir_check_label").innerHTML = "";
	   
  }
  else
  {
  //alert("The two passwords you entered are not the same \n" + "Please re_enter both now");
          document.getElementById("passwordconfircheck").src="images/error.jpg";
          document.getElementById("passwordconfircheck").style.display="";
          document.getElementById("passwordconfir_check_label").innerHTML = "两次密码不一致！";
	   //init.focus();
	  // init.select();
	   //return false;
	      right_passwords = false;
  }
		  //return true;
	  
}
/////////////////////电子邮件///////////////////////
function chkEmail()
{
   var temp = document.getElementById("memberEmail");
   //对电子邮件的验证
   var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
   if(!myreg.test(temp.value))
 {
        //alert('请输入有效邮箱！');
    document.getElementById("emailcheck").src="images/error.jpg";
    document.getElementById("emailcheck").style.display="";
	document.getElementById("email_check_label").innerHTML = "请输入有效邮箱！";
        //temp.focus();
    right_email= false;
  }
else
{
    document.getElementById("emailcheck").src="images/right.jpg";
    document.getElementById("emailcheck").style.display="";
	document.getElementById("email_check_label").innerHTML = "";
    right_email = true;
}

} 
/////////////////////电话///////////////////////////
function chkPhone()
{
   var phone = document.getElementById("memberPhone");
   var str = phone.value;
   var myphone= /^((?:\d{11})|(?:\d{4}-\d{7})|(?:\d{4}-\d{8}))$/;
   if(!myphone.test(str))
   {
    //alert("输入有效电话");
    document.getElementById("phonecheck").src="images/error.jpg";
    document.getElementById("phonecheck").style.display="";
    document.getElementById("phone_check_label").innerHTML = "输入有效电话";
    right_phone = false;
    }
    else
   {
    document.getElementById("phonecheck").src="images/right.jpg";
    document.getElementById("phonecheck").style.display="";
    document.getElementById("phone_check_label").innerHTML = "";
    right_phone = true;
    }
}
/////////////////////名字///////////////////////
function chkName(){
var name = document.getElementById("memberName");
var str  = name.value;  
str = str.replace(/\s+/g,""); 
if(str=="")   
{
   
    document.getElementById("namecheck").src="images/error.jpg";
    document.getElementById("namecheck").style.display="";
    document.getElementById("name_check_label").innerHTML = "请输入名字"; 
    right_name = false; return ;
                               
}
  var ts;      
  var tscode;      
  for (i=0;i<str.length;i++) {      
		      ts=str.substring(i);      
		      tscode=ts.charCodeAt();      
        if ((tscode<19968)||(tscode>40959)) {      
			         //alert("you must input chinese"); 
                 document.getElementById("namecheck").src="images/error.jpg";
    			 document.getElementById("namecheck").style.display="";
   				 document.getElementById("name_check_label").innerHTML = "请输入汉字";    
				 right_Name = false;
	             return;      
           }      
    } 
    document.getElementById("namecheck").src="images/right.jpg";
    document.getElementById("namecheck").style.display="";
    document.getElementById("name_check_label").innerHTML = ""; 
    right_Name = true; 
}
 ////////////////////////////////////////////   
function check()
{
    if( right_id == false||right_passwords == false||right_confpasswords ==false||right_email == false||right_phone == false||right_name == false||right_addr == false) 
        return false;
        else 
        return true;

}



 
